package com.home.school.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.home.school.bean.TLog;
import com.home.school.service.TLogService;
import com.home.school.vo.LogListVO;
import com.home.school.model.R;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author: cuiyutian1
 * @date: 2021/12/5 10:13
 * @description:
 */
@RestController
@RequestMapping("/api/log")
public class LogController {
    @Autowired
    private TLogService tLogService;

    /**
     * 操作日志 分页查询
     * @param bean
     * @return
     */
    @RequestMapping(value = "list", method = RequestMethod.POST)
    public R list(@RequestBody LogListVO bean){
        Page<TLog> page = new Page<>(bean.getPageNum(),bean.getPageSize());
        QueryWrapper<TLog> wrapper = new QueryWrapper<>();

        String userId = bean.getUserId();
        if(StringUtils.isNotEmpty(userId)){
            wrapper.eq("user_id",userId);
        }

        String createStartTime =bean.getCreateStartTime();
        if(StringUtils.isNotEmpty(createStartTime)){
            wrapper.ge("create_time",createStartTime);
        }

        String createEndTime = bean.getCreateEndTime();
        if(StringUtils.isNotEmpty(createEndTime)){
            wrapper.le("create_time",createEndTime);
        }

        wrapper.orderByDesc("id");
        IPage<TLog> iPage = tLogService.page(page, wrapper);
        return R.ok().data(iPage);
    }

}
